package com.kfm.service;

import com.kfm.dao.KfmFileMapper;
import com.kfm.model.KfmFile;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class KfmFileService {
    KfmFileMapper mapper;
    SqlSession sqlSession;
    InputStream inputStream;
    public KfmFileService(){
        try {
            inputStream = Resources.getResourceAsStream("mybatis-config.xml");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        SqlSessionFactory build = builder.build(inputStream);
        sqlSession = build.openSession(true);
        mapper = sqlSession.getMapper(KfmFileMapper.class);
    }
    public List<KfmFile> selectAll() {
        return mapper.selectAll();
    }

    public KfmFile selectById() {
        return mapper.selectById(1);
    }
}
